Demo of Eddie, the Code Editor

Version 4

by Alyce Watson [http://alycesrestaurant.com/]

Home

LB Wire Frame Lib

Stylebits - Listboxes

IExpress

Prompt

Icons

Screen Capture

Eddie's Lessons

Combobox

Scrolling Texteditor

Nested If/Then

Sprite Byte

Eddie

Moving Listbox Items

Newsletter help

Submissions

Index


'** Eddie - an LB Code Editor
    'version 4
    'adds branch label combobox
    'moves texteditor and graphicbox down to make room for combobox
    'fill branch combo when opening file
    'checks number or rows in timer routine
    'if number of rows has changed, refill branch combobox
    'when user selects branch, puts that branch at origin
    'add Tools menu and *goto line tool*

if val(Version$)<4.02 then
    notice "For Liberty BASIC v4.02 and higher."
    'the *!origin* command in LB4.02 has designator vars in this order - col then row
    'in LB4.01 the order was row then col
    'also - in LB4.01 the *!origin?* command was broken and the row receiver var didn't get filled
    end
end if

[VariableSetup]
    '#f will be the handle for opening files
    'note that Version$ is a reserved variable name
    EddieVersion$ = "4"
    'path to Liberty.exe for running programs:
    LibertyExe$ = ""
    'name of ini file for this version of Eddie
    IniFile$ = "eddie4.ini"
    'variable to hold contents of texteditor
    text$ = ""
    'filename for writing a temp file to disk
    tempfile$ = DefaultDir$ + "\tempfile.bas"
    'filename for user saving file to disk
    savefile$ = ""

    dim branch$(1000)       'array to hold branch labels
    branch$(1) = ""  'first designation takes you to top of code

[WindowSetup]
    NOMAINWIN
    WindowWidth = 600 : WindowHeight = 360
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)

[ControlSetup]
'menus
Menu        #1, "&File", "&New", [new], "&Open", [open], "&Save", [save],_
            |,"&Print", [print], "E&xit", [quit]

'LB will place Edit menu where you specify in list of menus
'do not use ampersand & in Edit menu caption
Menu        #1, "Edit"
Menu        #1, "&Run","R&un", [run]
Menu        #1, "&Tools", "&Go to Line", [gotoLine]
Menu        #1, "&Help", "He&lp", [help], "&About", [about]

'buttons for a toolbar lookalike
button      #1.new, "New",[new],UL, 0, 0, 45, 20
button      #1.open, "Open",[open],UL, 45, 0, 45, 20
button      #1.save, "Save",[save],UL, 90, 0, 45, 20
button      #1.print, "Print",[print],UL, 135, 0, 45, 20
button      #1.cut, "Cut",[cut],UL, 190, 0, 45, 20
button      #1.copy, "Copy",[copy],UL, 235, 0, 45, 20
button      #1.paste, "Paste",[paste],UL, 280, 0, 45, 20
button      #1.run, "Run",[run],UL, 335, 0, 45, 20
button      #1.help, "Help",[help],UL, 380, 0, 45, 20

'a graphicbox for line numbers
stylebits #1.g, 0,_WS_BORDER,0,0
graphicbox  #1.g, 0, 52, 39, 230
'a texteditor
texteditor  #1.te, 39, 52, 545, 250

'combobox for branch labels
combobox #1.c, branch$(),[chooseBranch],40,22,385,300

Open "Eddie - an LB Code Editor v." + EddieVersion$ for Window as #1
    'trap the close event, if the user closes the
    'window with the X button
    #1 "trapclose [quit]"

    'set the font for the window and controls
    #1 "font ms_sans_serif 10"

    'set a custom font for the texteditor
    #1.te "!font courier_new 0 16"
    'set up the graphicbox
    #1.g "down; fill Buttonface; backcolor buttonface; flush"
    'use the same font as the texteditor
    #1.g "font courier_new 0 16"
    #1.g "autoresize"

    'cause the texteditor to resize automatically
    'when the user resizes the window
    #1.te "!autoresize"

    'select item in combobox
    #1.c "selectindex 1"

    TIMER 50, [activateTimer]    'initialize the timer

[loop]
    Wait

[quit]
    TIMER 0
    close #1 : END

[activateTimer]
    'check the number of lines of text
    #1.te "!lines rowcount"
    'if it has changed, refill branch label combobox
    if rowcount<>lastRowcount then gosub [fillBranch]
    'new lastRowcount is this rowcount
    lastRowcount=rowcount

    'check the number of the row at the top of the texteditor
     #1.te "!origin? col row"
     'if it is the same as last check, do nothing
     if row = lastRow then wait
    'turn off timer for this routine
     TIMER 0
     'new lastRow is current row, for next check
     lastRow = row
     'delete previously named drawing segment called *linenums*
     #1.g "delsegment linenums"
     'location to start drawing line numbers
     #1.g "place 2 14"
     'fill with default buttonface color to erase previous line numbers
     #1.g "fill buttonface"
     'use top row number as starting number for line numbers
     for i = row to row+100
        'using() aligns the numbers for us
         num$=using("####",i)
         #1.g "\";num$
     next
     'flush and give this segment the name *linenums*
     #1.g "flush linenums"
     'start timer again
     TIMER 50, [activateTimer]
     wait

[new]
    #1.te "!CLS"
    Wait

[open]
    TIMER 0
    filedialog "Open","*.bas",openfile$
    if openfile$="" then wait

    open openfile$ for input as #f
    'dump contents of file into texteditor
    #1.te "!contents #f"
    close #f
    gosub [fillBranch]
    TIMER 50, [activateTimer]
    Wait

[save]
    TIMER 0
    'if the word SAVE is in the caption, LB
    'automatically creates a SAVE dialog
    filedialog "Save As","*.bas",savefile$
    if savefile$="" then wait

    'make sure that user had given the file a *bas extension
    if right$(lower$(savefile$),4)<>".bas" then
        savefile$=savefile$+".bas"
    end if

    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    if text$="" then
        notice "No file to save."
        wait
    end if

    'open file and write text to it
    open savefile$ for output as #f
        #f text$
    close #f
    TIMER 50, [activateTimer]
    Wait

[print]
    TIMER 0
    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    if text$="" then
        notice "No text to print."
        wait
    end if

    'send text to printer
    lprint text$
    'cause printing to happen now
    dump
    TIMER 50, [activateTimer]
    Wait

[help]
    'place code here
    Wait

[about]
    'place code here
    Wait

[cut]
    #1.te "!cut"
    wait

[copy]
    #1.te "!copy"
    wait

[paste]
    #1.te "!paste"
    wait

[run]
    TIMER 0
    'go to routine to get liberty.exe path
    'into variable LibertyExe$$
    gosub [GetLibertyPath]
    'if we can't find the path to Liberty BASIC
    'we must abort the RUN operation
    if LibertyExe$="" then wait

    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    'if there is no code, then abort the RUN operation
    if text$="" then
        notice "No code to run."
        wait
    end if

    'open file and write text to it
    open tempfile$ for output as #f
        print #f, text$
    close #f

    'use RUN command to run Liberty BASIC
    'with this file loaded
    'put filename in quotation marks, so
    'that spaces do not break up the filename
    RUN LibertyExe$ + " " + chr$(34) + tempfile$ + chr$(34)
    TIMER 50, [activateTimer]
    wait

[GetLibertyPath]
    timer 0
    'file to store path info is IniFile$
    'open for append to see if file exists
    'attempting to open a nonexistent file for INPUT causes an error
    open IniFile$ for append as #f
    lenFile = LOF(#f)
    close #f

    'if the length = 0, the file doesn't exist
    if lenFile=0 then
        filedialog "Find Liberty.exe","*liberty*.exe",LibertyExe$
        if LibertyExe$="" then
            'the user cancelled the filedialog
            notice "Liberty.exe not found."
        else
            'the user selected liberty.exe on his computer
            'open the ini file and store the information
            open IniFile$ for output as #f
            print #f, LibertyExe$
            close #f
        end if
    else
        'if the length is greater than 0, the file exists
        'open it for input and read the first line
        'into the variable LibertyExe$
        open IniFile$ for input as #f
        line input #f, LibertyExe$
        close #f
    end if
    TIMER 50, [activateTimer]
    RETURN

[fillBranch]
    timer 0
    #1.te "!lines rowcount"
    #1.te "!origin? col row"

    REDIM branch$(rowcount)
    branch$(1)=""

    bx=2
    For i=1 to rowcount
        #1.te,"!line ";i;" line$";
            If Left$(Trim$(line$),1)="[" Then
                branch$(bx)=Trim$(line$)
                bx=bx+1
            End If
            If Lower$(Word$(line$,1))="function" Then
                branch$(bx)=Trim$(line$)
                bx=bx+1
            End If
            If Lower$(Word$(line$,1))="sub" Then
                branch$(bx)=Trim$(line$)
                bx=bx+1
            End If
    Next i

    #1.c "reload"
    #1.c "selectindex 1";
    TIMER 50, [activateTimer]
    return

[gotoLine]
    timer 0
    #1.te "!lines rowcount"
    gotoLine=rowcount
    msg$="Go to line? Max is ";gotoLine
    prompt msg$;gotoLine
    if gotoLine>rowcount then gotoLine=rowcount
    if gotoLine<1 then gotoLine=1
    #1.te "!origin 1 ";gotoLine
    #1.te "!setfocus"
    TIMER 50, [activateTimer]
    wait

[chooseBranch]
   '** CHOOSE BRANCH, SET EDITOR TO THAT POSITION
    timer 0
    #1.c "selection? branchselect$"

    'user selected top of code
    If branchselect$="" Then
        #1.te "!origin 1 1"
        #1.te "!setfocus"
        TIMER 50, [activateTimer]
        Wait
    End If

    For i = 1 TO rowcount
       #1.te "!line ";i;" line$"
          If Trim$(line$)= branchselect$ Then
            #1.te "!origin 1 "
            #1.te "!setfocus"
            exit for
          End If
    Next i
    TIMER 50, [activateTimer]
    Wait


Home

LB Wire Frame Lib

Stylebits - Listboxes

IExpress

Prompt

Icons

Screen Capture

Eddie's Lessons

Combobox

Scrolling Texteditor

Nested If/Then

Sprite Byte

Eddie

Moving Listbox Items

Newsletter help

Submissions

Index